Repository navigation
fix(apply-edits): make batch failures actionable - #100
Merged
Merged
Conversation
Guide callers to group hunks by file and use exact current target text. Report invalid and stale bounds with specific recovery steps, and distinguish retries after zero writes, partial writes, and argument corruption.
INK-Q
requested changes
Nov 28, 2026
INK-Q
left a comment
Owner
There was a problem hiding this comment.
Thanks @iazrael for investigating misgrouped multi-file hunks and improving the recovery wording and EOF line-count accuracy!
A few P0/P1 regressions need to be addressed before merging:
P0 / P1 (Must Fix)
- Throwing on
sLine > totalLinesingetLineWindowOffsetsbreaks existing line-drift detection (src/tools/apply-edits.ts:151-154):- Previously,
sLine > totalLinesreturned{ windowStart: text.length, windowEnd: text.length }, allowingplanHunksForContentto scan the file for an exact match outside the requested window (Exact match found outside range at L...) or emit a closest-region snippet when a file shrank slightly andstartLinedrifted past EOF. - Throwing immediately inside
getLineWindowOffsetsbypasses drift detection entirely (and would block upcoming small-drift auto-recovery ondev). - Instead, keep
getLineWindowOffsetsreturning an empty window whensLine > totalLines, and reportstartLine N exceeds file length (M lines)only inside thefoundOffsets.length === 0path after confirming no global exact match exists (while still skipping emptyNearby lines).
- Previously,
- Empty-file edge case when popping EOF
lineStarts(src/tools/apply-edits.ts:371):- For a 0-byte file (
""),computeLineStarts("")returns[0], solineStarts.at(-1) === normalizedContent.length(0 === 0) pops[0]to[](totalLines = 0), causingstartLine: 1to fail withexceeds file length (0 lines)instead of normal target matching. Guard withif (normalizedContent.length > 0 && lineStarts.at(-1) === normalizedContent.length) lineStarts.pop();.
- For a 0-byte file (
- Regressions & bloat in
rules/AGENTS.md(+768 B) andsrc/mcp-server-core.ts:- Rewriting Rule 5 in
rules/AGENTS.mdadds+768 Bto the always-injected system prompt and removes core repository routing rules (consistent usage across Vue/HTML/CSS/docs/scripts/scratch, defaulting tobestEffort: truefor>=3files with<=6-8-file batches) while reversingbestEffortguidance ("Enable bestEffort: true only when partial writes are acceptable"). Please preserve the existing Rule 5 directives and keeprules/AGENTS.mdconcise. - In
src/mcp-server-core.ts, the updatedapply_editsdescription dropsverifytimeout/budget constraints (60s/4000 chars, 150s max) and(Desktop 2.0 Hub). Please keep those operational limits in the tool description (within the<= 1280 Bschema budget).
- Rewriting Rule 5 in
Checklist
- Preserve global exact-match drift detection when
startLine > totalLinesbefore falling back to the out-of-bounds length error - Guard
lineStarts.pop()for 0-byte empty files - Restore the removed
rules/AGENTS.mdRule 5 directives & keep delta minimal, and restoreverifytimeout/char limits inapply_editsdescription - Rebuild
dist/mcp-server.mjsand re-runnpm run typecheck && npm test && npm run validate
Address review P0/P1 feedback on batch-failure recovery: - getLineWindowOffsets returns an empty window when startLine exceeds the file length, so global exact-match drift detection still runs; the out-of-bounds length error is reported only after confirming no exact match exists, skipping empty Nearby lines. - Guard lineStarts.pop() for 0-byte files so startLine 1 matches normally. - Restore removed rules/AGENTS.md Rule 5 directives (repo routing across Vue/HTML/CSS/docs/scripts/scratch, bestEffort: true for >=3 files, serialization-corruption circuit break) and fold the grouping/recovery guidance in compactly (+505B vs +768B). - Restore verify timeout/char limits and (Desktop 2.0 Hub) in the apply_edits description within the 1280B schema budget (array 1265B, string 1119B). Rebuild dist/mcp-server.mjs; typecheck, 187 tests, and validate pass.
INK-Q
approved these changes
Nov 29, 2026
INK-Q
left a comment
Owner
There was a problem hiding this comment.
Thanks @iazrael for the clean follow-up commit! All previous P0/P1 items are verified resolved:
getLineWindowOffsetsnow rejects inverted ranges (requestedEnd < sLine) first while still allowingsLine > totalLinesto fall through to exact-match drift detection (and emits the concise EOF guidance only when no global exact match exists).lineStarts.pop()is properly guarded for 0-byte empty files and covered by a dedicated unit test.apply_editsschema description restores theverifytimeout/char limits (1,265 Barray /1,119 Bstring, safely within the1,280 Bcap), and Rule 5 restores multi-directory &bestEffortguidance.- Verified clean 3-way merge onto latest
origin/dev(3675109) with byte-for-bytedist/mcp-server.mjsesbuildparity.
Approving now — once the GitHub Actions CI checks finish green, we'll merge this into dev.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reproduction
A four-file edit arrived with all four hunks under a single changelog path. The original error showed empty nearby-line ranges. The regression test checks that a wrong-path request is rejected even when it contains a target that happens to match the wrong file, then verifies that the corrected batch applies.
Verification
npm run typecheckandnpm run validatepassed.npm testpassed all 185 tests and rebuilt the checked-in MCP bundle.node scripts/stress-benchmark.mjspassed all 11 scenarios.